/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.ta.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import com.thinkgem.jeesite.modules.ta.entity.WorkListForWorklistNode;
import com.thinkgem.jeesite.modules.ta.service.WorkListForWorklistNodeService;

/**
 * 待办事务Controller
 * 
 * @author TTAO
 * @version 2017-05-26
 */
@Controller
@RequestMapping(value = "${adminPath}/ta/workListForWorklistNode")
public class WorkListForWorklistNodeController extends BaseController {

	@Autowired
	private WorkListForWorklistNodeService workListForWorklistNodeService;

	@ModelAttribute
	public WorkListForWorklistNode get(@RequestParam(required = false) String id) {
		WorkListForWorklistNode entity = null;
		if (StringUtils.isNotBlank(id)) {
			entity = workListForWorklistNodeService.get(id);
		}
		if (entity == null) {
			entity = new WorkListForWorklistNode();
		}
		return entity;
	}

	@RequiresPermissions("ta:workListForWorklistNode:view")
	@RequestMapping(value = { "list", "" })
	public String list(WorkListForWorklistNode workListForWorklistNode,
			HttpServletRequest request, HttpServletResponse response,
			Model model) {
		User user = UserUtils.getUser();
		if (user == null) {
			return "modules/sys/sysLogin";
		}
		String userId = user.getNo();
		workListForWorklistNode.setUserid(userId);
		Page<WorkListForWorklistNode> page = workListForWorklistNodeService
				.findPage(new Page<WorkListForWorklistNode>(request, response),
						workListForWorklistNode);

		model.addAttribute("page", page);
		return "modules/ta/workListForWorklistNodeList";
	}

	@RequiresPermissions("ta:workListForWorklistNode:view")
	@RequestMapping(value = "form")
	public String form(WorkListForWorklistNode workListForWorklistNode,
			Model model) {
		model.addAttribute("workListForWorklistNode", workListForWorklistNode);
		return "modules/ta/workListForWorklistNodeForm";
	}

	@RequiresPermissions("ta:workListForWorklistNode:edit")
	@RequestMapping(value = "save")
	public String save(WorkListForWorklistNode workListForWorklistNode,
			Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, workListForWorklistNode)) {
			return form(workListForWorklistNode, model);
		}
		workListForWorklistNodeService.save(workListForWorklistNode);
		addMessage(redirectAttributes, "保存代办事务成功");
		return "redirect:" + Global.getAdminPath()
				+ "/ta/workListForWorklistNode/?repage";
	}

	@RequiresPermissions("ta:workListForWorklistNode:edit")
	@RequestMapping(value = "delete")
	public String delete(WorkListForWorklistNode workListForWorklistNode,
			RedirectAttributes redirectAttributes) {
		workListForWorklistNodeService.delete(workListForWorklistNode);
		addMessage(redirectAttributes, "删除代办事务成功");
		return "redirect:" + Global.getAdminPath()
				+ "/ta/workListForWorklistNode/?repage";
	}

}